#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 22, M = 80, K = 1010;
int v1[K], v2[K], w[K];
int f[N][M];
int n, m, k;
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= k; i++) cin >> v1[i] >> v2[i] >> w[i];
    memset(f, 0x3f, sizeof f);
    f[0][0] = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = n; j >= 0; j--)
        {
            for (int l = m; l >= 0; l--)
            {
                f[j][l] = min(f[j][l], f[max(0, j - v1[i])][max(0, l - v2[i])] + w[i]);
            }
        }
    }
    cout << f[n][m] << endl;
    return 0;
}